package demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class TabsListNew {
	public static String tabs[] = { "┣", "┃", "┗","　"};

	public static void main(String[] args) {

		String name[][] = { { "1", "省高级法院外网建设", "0" }, { "2", "公开", "1" },
				{ "3", "法院公告", "2" }, { "4", "判决文书", "2" },{ "5", "民事案件", "4" }, { "6", "刑事案件", "4" }, { "7", "服务", "1" },
				{ "8", "在线咨询", "7" }, { "9", "立案预约", "7" },{ "10", "诉讼服务", "7" },{ "11", "诉讼指南", "10" },{ "12", "司法公开指南", "10" },{ "13", "政法指南", "10" },
				{ "14", "省高级法院外网建设", "0" },{ "15", "司法公开指南1", "12" },{ "16", "刑事案件1", "6" },{ "17", "刑事案件2", "6" },
				{ "18", "判决文书", "2" },
				{ "20", "省高级法院外网建设子1", "14" }};

		System.out.println("ROOT");
		System.out.println("-----------------------------------");
		List<String[]> list = Arrays.asList(name);
		
		TreeMap<String, List<String[]>> parentMap = new TreeMap<String, List<String[]>>();
		for (String[] s : list) {
			List<String[]> subList = null;
			subList=parentMap.get(s[2]);
			if (subList == null) {
				subList = new ArrayList<String[]>();
				parentMap.put(s[2], subList);
			}  
			subList.add(s);
		}
		
		List<String[]> root = parentMap.get("0");
		int  prefixTabs[]=new int[99];
		for (int i=0;i<root.size();i++ ) {
			String[] node=root.get(i);
			if(i==root.size()-1){
				prefixTabs[0]=3;
				System.out.println(tabs[2] + node[1]);
			}else{
				prefixTabs[0]=1;
				System.out.println(tabs[0] + node[1]);
			}
			prefixTabs[1]=3;
			getLeaf(node,prefixTabs,1, parentMap);
		}
	}

	private static void getLeaf(String[] node,int[] prefixTabs, int leverCount,Map<String, List<String[]>> parentMap) {
		// {"┣","┃","┗","　"}
		if (parentMap.get(node[0]) != null) {
			int len = parentMap.get(node[0]).size();//子节点的个数
			for (int i=0;i<len;i++) {
				String[] n=parentMap.get(node[0]).get(i);
				for(int j=0;j<leverCount;j++){
					System.out.print(tabs[prefixTabs[j]]);
			    }
				if (i == len-1) {
					prefixTabs[leverCount]=3;
					System.out.println(tabs[2] + n[1]);
				} else {   
					prefixTabs[leverCount]=1;
					System.out.println(tabs[0] + n[1]);
				}
				    prefixTabs[leverCount+1]=3;
			 getLeaf(n,prefixTabs,leverCount+1,parentMap);
		   }
	    }
	}
}
